package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity {

    private Button mButton;
    private TextView mTextView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EventBus.getDefault().register(this);
        mButton = findViewById(R.id.bt_main);
        mTextView = findViewById(R.id.tv_main);

        mButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN, priority = 1000, sticky = true)
    public void onMessage(messageEvent messageEvent) {
        mTextView.setText(messageEvent.getMess());
        Log.e("evenBus",messageEvent.getMess());
    }

    protected void onDestroy() {
        super.onDestroy();
        //移除所有粘性事件
        // EventBus.getDefault().removeAllStickyEvents();
        EventBus.getDefault().unregister(MainActivity.this);
    }
}